Repository navigation
Conversation
…000271) Hibernate Validator deprecated placing @Valid on a Map container (HV000271) — the annotation must instead be on the type argument. Since the Map value type is often untyped (Any/Object), the correct fix is to omit @field:Valid from Map properties entirely. Add {{^isMap}} guard to the container branch of beanValidation.mustache so that only List/Set/Array containers still get @field:Valid.
Trade-off: validation of map valuesFor a property like So the options are: keep Consequence: constraints declared inside The fuller fix — emitting |
|
Closing this since it does not properly fix the underlying issue. Dropping The right fix is to emit the type-use form Closing rather than causing more issues. |
Description
Hibernate Validator 9.1 deprecated placing
@Validdirectly on aMapcontainer, emitting aHV000271warning at startup:The
beanValidation.mustachetemplate adds@field:Validto all container properties (List,Map, …) whose items are not primitives. ForMapproperties the correct fix is to omit@field:Validentirely — annotating a type argument ofMap<K, Any>orMap<K, SomeModel>with@Validwould require type-use annotations, which the current codegen does not support, and for untyped maps (Anyvalues) there is nothing to validate anyway.Change
Add a
{{^isMap}}guard to the container branch ofbeanValidation.mustacheso that onlyList/Set/array-typed properties still get@field:Valid. Map-typed properties are left unannotated.Testing
@TestinKotlinSpringServerCodegenTest: generates a model with oneMap<String, Item>property and oneList<Item>property, then asserts that exactly one@field:Validannotation is present in the generated file (for the list only).Map<String, ComplexType>properties).Summary by cubic
Skip emitting
@field:Validon Map properties in Kotlin Spring codegen to prevent HV000271 warnings with Hibernate Validator 9.1. Lists/Sets/arrays are unchanged.kotlin-spring/beanValidation.mustacheto apply@field:Validonly whenisContainer && !isMap.@field:Valid; regenerated samples with no changes.Written for commit b959b17. Summary will update on new commits.